//
//  CheckBottomView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/21.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "CheckBottomView.h"

@implementation CheckBottomView{
    GLGWLabel * moneyLabel;
}

-(id)initWithFrame:(CGRect)aFrame inSuperView:(UIView *)aSuperView{
    if (self = [super initWithFrame:aFrame inSuperView:aSuperView]) {
        self.backgroundColor = [UIColor whiteColor];
        GLGWView * lineView = [[GLGWView alloc] initWithInSuperView:self];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(self);
            make.height.equalTo(@1);
        }];
        //
        NSArray * titArr = @[@"返回购物车",@"确认提交"];
        for (int i=0; i<2; i++) {
            GLGWButton * rightBut = [[GLGWButton alloc] initWithFrame:CGRectMake(KScreenWidth - kWidthProportion_In_iPhoneTriploid(195)+kWidthProportion_In_iPhoneTriploid(90)*i, kHeightProportion_In_iPhoneTriploid(11), kWidthProportion_In_iPhoneTriploid(90), kHeightProportion_In_iPhoneTriploid(40)) titleLableFont:SYSTEMFONT(12) titleColor:[UIColor whiteColor] inSuperView:self];
            rightBut.title = titArr[i];
            if (i==0) {
                rightBut.backgroundColor = [UIColor colorWithHexString:@"#A89A60" alpha:0.6];
                UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rightBut.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft) cornerRadii:CGSizeMake(rightBut.frame.size.height/2,rightBut.frame.size.height/2)];//圆角大小
                CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
                maskLayer.frame = rightBut.bounds;
                maskLayer.path = maskPath.CGPath;
                rightBut.layer.mask = maskLayer;
                //
            }else{
                rightBut.backgroundColor = [UIColor colorWithHexString:@"#A89A60"];
                UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rightBut.bounds byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomRight) cornerRadii:CGSizeMake(rightBut.frame.size.height/2,rightBut.frame.size.height/2)];//圆角大小
                CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
                maskLayer.frame = rightBut.bounds;
                maskLayer.path = maskPath.CGPath;
                rightBut.layer.mask = maskLayer;
            }
            rightBut.tag = 300+i;
            [rightBut addTarget:self action:@selector(bottomAction:) forControlEvents:UIControlEventTouchUpInside];
        }
        moneyLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(16) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self];
        [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(210));
            make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(20));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
        }];
        moneyLabel.text = @"￥0.00";
        //
        GLGWLabel * hejiLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self];
        hejiLabel.text = @"合计";
        [hejiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.centerY.equalTo(self->moneyLabel);
            make.right.equalTo(self->moneyLabel.mas_left).offset(-kWidthProportion_In_iPhoneTriploid(5));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
        }];
    }
    return self;
}

-(void)setMoneyFolot:(CGFloat)moneyFolot{
    _moneyFolot = moneyFolot;
    moneyLabel.text = [NSString stringWithFormat:@"￥%.2f",_moneyFolot];
}

-(void)bottomAction:(GLGWButton *)sender{
    if (self.Block_BottomAction) {
        self.Block_BottomAction(sender);
    }
}

@end
